package main

import (
	. "http";
	"strings";
	"io";
	"io/ioutil";
	"net";
	"syscall";
)


func getAuthPage(c *Conn, req *Request) {
	if strings.Index(req.Header["Accept"], "application/xrds+xml") != -1 {
		c.SetHeader("Content-Type", "application/xrds+xml;charset=utf-8");
		file, err := ioutil.ReadFile("openid.xml");
		if err != nil {
			panic("Openning file: ", err.String())
		}
		io.WriteString(c, string(file));
	}
	c.SetHeader("Content-Type", "text/html;charset=utf-8");
	io.WriteString(c, "<html><body><b>Hello, World!</b></body></html>");

}

func main() {
	Handle("/", HandlerFunc(getAuthPage));

	l, err := net.Listen("tcp", ":80");
	if err != nil {
		panic("Listen: ", err.String())
	}

	syscall.Seteuid(70);

	err = Serve(l, nil);
	l.Close();

	if err != nil {
		panic("Serve: ", err.String())
	}

}
